package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.Address;
import com.vf.admin.miaodong.entity.DynamicAlert;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class DynamicAlertDao extends BaseDao<DynamicAlert> {

    public List<DynamicAlert> page(Integer userId, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from dynamic_alert where userId=" + userId);
        sbStr.append(" order by createTime desc");

        String sql = sbStr.toString();
        return this.queryList(sql, paramList, DynamicAlert.class, splitPage);
    }

    public void add(DynamicAlert params) {
        super.add(params);
    }

    public void delParseDynamic(Integer fromUserId, Integer userId, Integer dynamicId) {
        String sql = "delete from dynamic_alert where fromUserId="+ fromUserId +" and userId="+ userId +" and dynamicId="+ dynamicId +" and type=1";
        this.del(sql, null);
    }

    public void delParseComment(Integer fromUserId, Integer userId, Integer dynamicId) {
        String sql = "delete from dynamic_alert where fromUserId="+ fromUserId +" and userId="+ userId +" and dynamicId="+ dynamicId +" and type=3";
        this.del(sql, null);
    }

    public void updateNick(Integer userId, String nick){
        String sql = " UPDATE dynamic_alert SET nick = ?  WHERE userId = ? ";
        ArrayList<Object> paramList = new ArrayList<>();
        paramList.add(nick);
        paramList.add(userId);
        this.update(sql,paramList);

        sql = " UPDATE dynamic_alert SET fromUserNick = ?  WHERE fromUserId = ? ";
        this.update(sql,paramList);
    }

    public void updatePic(Integer userId, String pic){
        String sql = " UPDATE dynamic_alert SET pic = ?  WHERE userId = ? ";
        ArrayList<Object> paramList = new ArrayList<>();
        paramList.add(pic);
        paramList.add(userId);
        this.update(sql,paramList);

        sql = " UPDATE dynamic_alert SET fromUserPic = ?  WHERE fromUserId = ? ";
        this.update(sql,paramList);
    }
}
